def data_coroutine():
    print("协程开始")
    value1 = yield 2
    print(f"接收到数据: {value1}")
    value2 = yield 3
    print(f"接收到数据: {value2}")
    value3 = yield 4
    print(f"接收到数据: {value3}")


def main2():
    coroutine = data_coroutine()
    # coroutine.send(f"hello")
    # for i in coroutine:
    #     print(i)
    #     coroutine.send(f"world {i}")

    # # 向协程发送数据
    try:
        print(next(coroutine))
        print(coroutine.send("Hello"))
        print(coroutine.send("Hello2"))
        print(coroutine.send("Hello3"))
        print(next(coroutine))
        print(coroutine.send("World"))
        res = next(coroutine)
        print(res)
    except StopIteration:
        print("生成器已终止")



def test():
    i = 0
    while (i < 5):
        temp = yield i ** 2
        print(temp)
        i += 1

def main():
    t = test()
    print(next(t))
    print(t.send("blank1"))
    print(t.send("blank2"))
    print(t.send("blank3"))
    print(next(t))

main()

"""
send与next都会触元素迭代
"""